package com.assist
{
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.events.MouseEvent;

	public class Helper
	{
		public static var test :Boolean = true;
		private static var _stage :Stage;
		private static var _instance :Helper = new Helper();
		private static var _shortcut :MovieClip;
		
		private var _mainSp :Sprite;
		private var _stage :Stage;
		
		public function Helper()
		{
		}
		
		public static function initStage(s:Stage) : void
		{
			_stage = s;
			_instance.initStage(s);
		}
		
		public function initStage(s:Stage) : void
		{
			//默认test为false
			if (test == false)
			{
				return;
			}
			this._stage = s;
			s.addEventListener(KeyboardEvent.KEY_UP, stageKeyUp);
			initInteraction();
			return;
		}
		
		private function stageKeyUp(event:KeyboardEvent) : void
		{
			if (event.keyCode == 113)
			{
				if (this._mainSp.stage == null)
				{
					this._stage.addChild(_mainSp);
				}
				else
				{
					this._stage.removeChild(_mainSp);
				}
			}
		}
		
		public static function backtrace(... args) : void
		{
		}// end function
		
		private static function initInteraction() : void
		{
			_shortcut = new MovieClip();
			_shortcut.buttonMode = true;
			_shortcut.useHandCursor = true;
			_shortcut.tabEnabled = false;
			_shortcut.graphics.beginFill(3355443, 0);
			_shortcut.graphics.drawRect(0, 0, 20, 20);
			
			var callback :Function = function (event :MouseEvent) : void
			{
				switchInteraction();
			}// end function
			
			var over :Function = function (event :MouseEvent) : void
			{
				_shortcut.graphics.clear();
				_shortcut.graphics.beginFill(16711680, 0.2);
				_shortcut.graphics.drawRect(0, 0, 20, 20);
			}// end function
			
			var out :Function = function (event :MouseEvent) : void
			{
				_shortcut.graphics.clear();
				_shortcut.graphics.beginFill(3355443, 0);
				_shortcut.graphics.drawRect(0, 0, 20, 20);
			}// end function
			
			var everyFrame :Function = function (event :Event) : void
			{
				_stage.addChild(_shortcut);
			}// end function
			
			_shortcut.addEventListener(MouseEvent.CLICK, callback);
			_shortcut.addEventListener(MouseEvent.MOUSE_OVER, over);
			_shortcut.addEventListener(MouseEvent.MOUSE_OUT, out);
			_shortcut.addEventListener(Event.ENTER_FRAME, everyFrame);
		}
		
		public static function switchInteraction() : void {
			
		}
	}
}